#!/usr/bin/perl

package <ModuleName>;

use strict;
use warnings;

use SADI::Simple 0.007;

#-----------------------------------------------------------------
# CGI HANDLER PART
#-----------------------------------------------------------------

use Log::Log4perl qw(:easy);
use base '<ServiceBaseClass>';  # 'SADI::Simple::SyncService' or 'SADI::Simple::AsyncService'

# send log messages at WARN level or higher to STDERR
Log::Log4perl->easy_init($WARN);

my %config = (
    ServiceName => '<ServiceName>',
    Description => '<ServiceDescription>',
    InputClass => '<InputOWLClassURI>',
    OutputClass => '<OutputOWLClassURI>',
<if(ServiceURL)>
    URL => '<ServiceURL>', 
<endif>
    Authority => '<ServiceAuthority>', 
    Provider => '<ContactEmailAddress>',
<if(ServiceTypeURI)>
    ServiceType => '<ServiceTypeURI>',
<endif>
    Authoritative => <IsAuthoritative>,
<if(NanoPublisher)>
    NanoPublisher => <NanoPublisher>,
<endif>
);

my $service = <ModuleName>->new(%config);
$service->handle_cgi_request;

#-----------------------------------------------------------------
# SERVICE IMPLEMENTATION PART
#-----------------------------------------------------------------

use RDF::Trine::Node::Resource;
use RDF::Trine::Node::Literal;
use RDF::Trine::Statement;

=head2 process_it

 Function: implements the business logic of a SADI service
 Args    : $inputs - ref to an array of RDF::Trine::Node::Resource
           $input_model - an RDF::Trine::Model containing the input RDF data
           $output_model - an RDF::Trine::Model containing the output RDF data
 Returns : nothing (service output is stored in $output_model)

=cut

sub process_it {

    my ($self, $inputs, $input_model, $output_model) = @_;

    foreach my $input (@$inputs) {  # $input is an RDF::Trine::Node::Resource
        
        # Log4perl 'easy mode' routines: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, ALWAYS
        INFO(sprintf('processing input %s', $input->uri));

        # Your code goes here...
        # For a 'Hello, World!' example, see the SYNOPSIS section of
        # http://search.cpan.org/dist/SADI-Simple/lib/SADI/Simple.pm 
		# Your code processes each $input and does something to it
		# you then attach the results to the $input node through some
		# $meaningful_property
		
		my $statement = RDF::Trine::Statement->new($input, $meaningful_property, $some_value);
		
		# add that statement to the model, together with a reference to the $input 
		# that it refers to	
		$output_model->add_statement($statement, $input);  # this second parameter is required for NanoPublishing
			                                               # if you are not a nanopublisher the second parameter is ignored 
			    
    	# if you are a NanoPublisher then you must add this line to the end of your loop, 
    	# if you are not, you can add it or not, but it will be ignored
    	$output_model->nanopublish_result_for($input);
    }

}
1;